<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/10 0010
 * Time: 15:21
 */

namespace app\common\model;


use think\Exception;

class WxConfig extends BaseModel
{
    protected $deleteTime = false;

    /**
     * 保存数据
     * @param $param
     * @return \think\response\Json
     * @throws \Exception
     */
    public static function saveInfo($param) {
        try {
            // 删除老数据
            self::destroy([]);
            // 保存新数据
            $data = [];
            foreach ($param as $k => $v) {
                $data[] = [
                    'key' => $k,
                    'value' => $v,
                    'remark' => self::getRemark($k)
                ];
            }
            trace($data, 'wx_config_data');
            (new self)->saveAll($data);
            return return_data('保存成功！');
        } catch (Exception $e) {
            return return_data($e->getMessage(), 1);
        }
    }

    /**
     * 获取配置的描述信息
     * @param $k
     * @return mixed
     */
    private static function getRemark($k) {
        $array = [
            'wxapp_title' => '小程序title',
            'top_text_color' => '头部文字颜色',
            'top_background_color' => '头部背景颜色',
        ];
        return $array[$k];
    }

}